﻿Imports System
Imports System.Web

Partial Public Class Helper
    Public Enum ApplicationPathType
        ''' <summary>
        ''' Internal or Local URLs do not include Domain name
        ''' and never end in "\"
        ''' </summary>
        Internal
        ''' <summary>
        ''' External or Absolute URLs include Domain and http or https
        ''' in addtion to the Internal or local Application Path
        ''' </summary>
        External
    End Enum
    ''' <summary>
    ''' HttpContext.Current.Request.ApplicationPath
    ''' Never ends with "/"
    ''' </summary>
    ''' <returns>Application Path</returns>
    Public Shared Function ApplicationPath() As [String]
        Return ApplicationPath(ApplicationPathType.Internal)
    End Function
    ''' <summary>
    ''' HttpContext.Current.Request.ApplicationPath
    ''' Never ends with "/"
    ''' </summary>
    ''' <returns>Application Path</returns>
    Public Shared Function ApplicationPath(ByVal urlType As ApplicationPathType) As [String]
        If urlType = ApplicationPathType.Internal Then
            Return If((HttpContext.Current.Request.ApplicationPath = "/"), "", HttpContext.Current.Request.ApplicationPath)
        Else
            Return (If((HttpContext.Current.Request.IsSecureConnection), "https://", "http://")) + HttpContext.Current.Request.Url.Host + (If(HttpContext.Current.Request.Url.Port.ToString().IndexOf("80") = 0, "", ":" & (HttpContext.Current.Request.Url.Port.ToString()))) + ApplicationPath(ApplicationPathType.Internal)
        End If
    End Function
End Class
